extends KinematicBody2D


onready var icon = $"Sprite"
onready var anim = $"BlinkAnimation"

var velocity = Vector2.ZERO
var target_body

func _physics_process(delta):
	if target_body == null:
		if velocity == Vector2.ZERO:
			return
		velocity = velocity.move_toward(Vector2.ZERO, 6)
		move_and_slide(velocity)
	else:
		var tar_posion = target_body.get_global_position()
		var direct = get_global_position().direction_to(tar_posion)
		velocity = velocity.move_toward(direct * 50, 6)
		move_and_slide(velocity)
	if velocity.x != 0:
		icon.set_flip_h(velocity.x < 0)

func _on_Area2D_area_entered(area):
	print("em:: _on_Area2D_area_entered, position=", area.global_position)
	target_body = area
	pass # Replace with function body.


func _on_Area2D_area_exited(area):
	print("em:: _on_Area2D_area_exited")
	target_body = null
	pass # Replace with function body.
